package com.lyn.utils;

import android.text.TextUtils;


public class FilterStringUtil {

    public static String filterName(String name){
        if (!TextUtils.isEmpty(name)){
            StringBuffer stringBuffer=new StringBuffer();
            int length = name.length();
            for (int i = 0; i < length; i++) {
                String substring = name.substring(i,i+1);
                if (i==0){
                    stringBuffer.append(substring);
                }else {
                    stringBuffer.append("*");
                }
            }
            return stringBuffer.toString();
        }
        return name;
    }

    public static String filterIdCard(String idCard){
        if (!TextUtils.isEmpty(idCard)){
            if (!IdCardValidatorUtil.isValidate18IdCard(idCard)){
                return idCard;
            }
            StringBuffer stringBuffer=new StringBuffer();
            int length = idCard.length();
            for (int i = 0; i < length; i++) {
                String substring = idCard.substring(i,i+1);
                if (i>13){
                    stringBuffer.append(substring);
                }else {
                    stringBuffer.append("*");
                }
            }
            return stringBuffer.toString();
        }
        return idCard;
    }

    public static String filterPhone(String phone){
        if (!TextUtils.isEmpty(phone)){
            if (!CheckFieldUtil.checkPhone(phone)){
                return phone;
            }
            StringBuffer stringBuffer=new StringBuffer();
            int length = phone.length();
            for (int i = 0; i < length; i++) {
                String substring = phone.substring(i,i+1);
                if (i>6){
                    stringBuffer.append(substring);
                }else {
                    stringBuffer.append("*");
                }
            }
            return stringBuffer.toString();
        }
        return phone;
    }


}
